package com.hdax.dm.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdax.dm.dao.scheduler.DmScheduler2Mapper;
import com.hdax.dm.dao.scheduler.DmSchedulerSeatMapper;
import com.hdax.dm.entity.scheduler.DmSchedulerSeat;
import com.hdax.dm.entity.scheduler.DmSchedulerSeatPrice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(path = "/rest/schedulerSeat")
@Api(value = "排期座位信息接口",tags = "排期座位信息接口")
public class DmSchedulerSeatRestService {

    @Resource
    private DmSchedulerSeatMapper dmSchedulerSeatMapper;
    @Resource
    private DmScheduler2Mapper scheduler2Mapper;


    @ApiOperation(value = "查询座位数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleId", required = true, type = "long"),
            @ApiImplicitParam(name = "areaLevel", required = true, type = "long")
    })
    @PostMapping(path = "/seatCount")
    public Long seatCount(@RequestParam("scheduleId")Long scheduleId,@RequestParam("areaLevel")Long areaLevel){
        QueryWrapper<DmSchedulerSeat> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("scheduleId",scheduleId);
        queryWrapper.eq("areaLevel",areaLevel);
        queryWrapper.eq("status",3L);
        queryWrapper.isNotNull("orderNo");
        queryWrapper.isNotNull("userId");
        return Long.valueOf(dmSchedulerSeatMapper.selectCount(queryWrapper));
    }

    @ApiOperation(value = "查询座位信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleId", required = true, type = "long")
    })
    @PostMapping(path = "/getSeat")
    public List<DmSchedulerSeat> getSeat(@RequestParam("scheduleId")Long scheduleId){
        QueryWrapper<DmSchedulerSeat> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("scheduleId",scheduleId);
        return dmSchedulerSeatMapper.selectList(queryWrapper);
    }

    //查询排期座位信息
    @PostMapping(path = "/getScheduleSeat")
    public DmSchedulerSeat getScheduleSeat(@RequestParam("scheduleId")Long scheduleId,
                                           @RequestParam("x")Long x,@RequestParam("y")Long y){
        QueryWrapper<DmSchedulerSeat> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("scheduleId",scheduleId);
        queryWrapper.eq("x",x);
        queryWrapper.eq("y",y);
        return dmSchedulerSeatMapper.selectOne(queryWrapper);
    }

    //修改排期座位信息
    @PostMapping(path = "/updateScheduleSeat")
    public int updateScheduleSeat(@RequestBody DmSchedulerSeat dmSchedulerSeat){
        return dmSchedulerSeatMapper.updateById(dmSchedulerSeat);
    }

    //查询排期座位信息根据订单编号
    @PostMapping(path = "/getScheduleSeatbyOrderNo")
    public List<DmSchedulerSeat> getScheduleSeatbyOrderNo(@RequestParam("orderNo")String orderNo){
        QueryWrapper<DmSchedulerSeat> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("orderNo",orderNo);
        return dmSchedulerSeatMapper.selectList(queryWrapper);
    }

    //自定义修改排期座位
    @PostMapping(path = "/hyupdateScheduleSeat")
    public int hyupdateScheduleSeat(@RequestBody String orderNo){
        return scheduler2Mapper.changeScheduleSeat(orderNo);
    }

}
